<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>测试for循环速度优化无效</title>
	</head>
	<body>
		<script type="text/javascript">
			var max = 12345678,
				arr = [];
			var s = 20;
			var r = Math.round(max / s);
			console.log(r)
			for (var i = 0; i < max; i++) {
				var item = {
					toi: i,
					name: i
				};
				arr.push(item);
			}
			
			function rs(arr, to_i, to_len) {
				for (to_i; to_i < to_len; to_i++) {
					var item = arr[to_i];
					if (item.toi == 12345677) {
						console.log((new Date().getTime()) - tiem);
						return (new Date().getTime()) - tiem;
					}
				}
			}
			//var istrue=rs(arr,r,max);
			var tiemrs = [];
			var istrue = -1;
			var rr = s;
			var num = 0;
			var max1 = r
			var tiem = new Date().getTime();
			for (var i = 0; i < rr; i++) {
				sss(num, max1);
				num = max1;
				max1 += r;
				if (max1 > max) {
					max1 = max;
				}
			};
			
		async function sss(num, max1) {
				console.log(num, max1);
				var tiemr = setInterval(function() {
					istrue = rs(arr, num, max1);
					if (istrue > 0) {	console.log("fff");
						for (var t = 0; t < tiemrs.length; t++) {
							clearInterval(tiemrs[t]);
						
						}
					}
				});
				tiemrs.push(tiemr);
			};
		</script>
	</body>
</html>
